package com.me.jingdongshop.ui.activity;

import android.os.Message;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;

import com.me.common.base.BaseActivity;
import com.me.jingdongshop.R;
import com.me.jingdongshop.model.bean.HotproductBean;
import com.me.jingdongshop.model.protocol.IHttpService;
import com.me.jingdongshop.presenter.TestFragmentPre;
import com.me.jingdongshop.ui.adapter.HomeHotItemAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by wuer on 2017/5/7/007.
 * 热门单品
 */
public class HomeHotItemActivity extends BaseActivity{
    private ImageView ivHeadBack;
    private ImageView ivHeadCart;
    private RecyclerView recyclerView;

    private HomeHotItemAdapter homeHotItemAdapter;
    private HotproductBean hotproductBean;
    private List<HotproductBean.ProductListBean> myProductListBeen;
    @Override
    public int getLayoutRes() {
        return R.layout.activity_home_hot_item;
    }

    @Override
    public void initView() {
        ivHeadBack = (ImageView) findViewById(R.id.iv_head_back);
        ivHeadBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        ivHeadCart = (ImageView) findViewById(R.id.iv_head_cart);
}

    @Override
    public void initListener() {

    }
    TestFragmentPre mTestFragmentPre;
    @Override
    public void initData() {
        mTestFragmentPre = new TestFragmentPre(this);
        mTestFragmentPre.getHotproduct();
    }

    @Override
    public void onClick(View v, int id) {

    }

    @Override
    public void onHttpSuccess(int reqType, Message msg) {
        if (reqType== IHttpService.HTTP_HOTPRODUCT){
            hotproductBean= (HotproductBean) msg.obj;
            myProductListBeen=hotproductBean.getProductList();
            List<List<HotproductBean.ProductListBean>> list=new ArrayList<>();
            list.add(myProductListBeen);
            initRecyclerView();
        }
    }

    private void initRecyclerView() {
        recyclerView = (RecyclerView) findViewById(R.id.home_rv_hot_item);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        homeHotItemAdapter = new HomeHotItemAdapter(myProductListBeen);
        recyclerView.setAdapter(homeHotItemAdapter);
        homeHotItemAdapter.notifyDataSetChanged();
    }

    @Override
    public void onHttpError(int reqType, String error) {
    }
}
